package com.itheima.udp;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

//练习：
//发送端：数据来源于键盘录入，直到录入的数据是886，发送数据接收
//接受端：接受端不知道发送端什么时候停止数据，故采用死循环接受
public class SockdetDemoPrice02 {
    public static void main(String[] args) throws IOException {
        DatagramSocket da = new DatagramSocket(8080);
        while (true) {
            byte[] bytes = new byte[1024];
            DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
            da.receive(dp);
            byte[] data = dp.getData();
            int length = dp.getLength();
            System.out.println(new String(data, 0, length));
        }
        //da.close();
    }

}

